﻿using AutoMapper;
using DFGK_WMS.Context;
using DFGK_WMS.IRepository;
using DFGK_WMS.Model.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace DFGK_WMS.Repository
{
    public class TInterfaceLogRepository : BaseRepository<TInterfaceLog>, ITInterfaceLogRepository
    {
        public TInterfaceLogRepository(DFGK_DB context, IMapper mapper) : base(context, mapper)
        {
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="uid"></param>
        /// <returns></returns>
        public bool DelTInter(int uid)
        {
            try
            {
                var del = Context.TInterfaceLogs.Find(uid);
                if (del != null)
                {
                    Context.TInterfaceLogs.Remove(del);
                    return Context.SaveChanges() > 0;
                }
                return false;
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 查询显示
        /// </summary>
        /// <param name="rid"></param>
        /// <param name="staid"></param>
        /// <param name="jname"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalCount"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public List<TInterfaceLog> GetTInterfaceLogList(int? logid, int? staid, string? jname, int pageIndex, int pageSize, out int totalCount)
        {
            try
            {
                var list = Context.TInterfaceLogs.AsQueryable();
                if (logid.HasValue)
                {
                    list = list.Where(x => x.LogType == logid);
                }
                if (staid.HasValue)
                {
                    list = list.Where(x => x.Status == staid);
                }
                if (!string.IsNullOrEmpty(jname))
                {
                    list = list.Where(c => c.Name.Contains(jname));
                }
                totalCount = list.Count();
                list = list.OrderBy(x => x.CreateDate).Skip((pageIndex - 1) * pageSize).Take(pageSize);
                return list.ToList();
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
